package com.kakavr.game.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.collect.Maps;
import com.kakavr.base.controller.BaseController;
import com.kakavr.base.exception.ValidateParamException;
import com.kakavr.game.service.IGameBasicService;
import com.kakavr.recharge.service.IRechargeRuleService;
import com.kakavr.result.MsgResult;
import com.kakavr.result.constant.MsgConstants;
import com.kakavr.util.SessionUtils;
/**
 * 游戏机上请求
 * @author gang.yang
 *
 */
@RestController
@RequestMapping("game")
public class GameController extends BaseController {
	
	@Resource
	private IGameBasicService gameBasicService;
	@Resource
	private IRechargeRuleService rechargeRuleService;
	
	/**
	 * 最新游戏
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "selectNewList", method = RequestMethod.GET)
	public Map<String, Object> selectNewList(HttpServletRequest request){
		return MsgResult.okResultData(gameBasicService.selectNewGameList(Maps.newHashMap()));
	}
	
	/**
	 * 店铺充值规则列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "selectRecRule", method = RequestMethod.GET)
	public Map<String, Object> selectRechargeRule(HttpServletRequest request){
		Map<String,Object> map = Maps.newHashMap();
		map.put("regionId", SessionUtils.getCurUser().get("regionId"));
		return MsgResult.okResultData(rechargeRuleService.selectList(map));
		
	}
	
	/**
	 * 游戏列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "selectGameList", method = RequestMethod.GET)
	public Map<String, Object> selectGameList(HttpServletRequest request){
		Map<String, Object> map = this.initPaginationParams(request);
		map.put("category", request.getParameter("category"));
		map.put("gameCount", 8);
		return MsgResult.okResultData(gameBasicService
				.selectGameBasicByPage(map));
	}
	/**
	 * 游戏详情
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "selectGameInfo", method = RequestMethod.GET)
	public Map<String, Object> selectGameInfo(HttpServletRequest request){
		String id = request.getParameter("id");
		if(StringUtils.isBlank(id)){
			throw new ValidateParamException(MsgConstants.MSG_CODE_1001, MsgConstants.MSG_CONTENT_1001,"游戏id");
		}
		Map<String,Object> map = Maps.newHashMap();
		map.put("id", id);
		return MsgResult.okResultData(gameBasicService
				.selectGameInfo(map));
	}	

}
